package view;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;

import business.Aluno;
import business.Funcionario;
import business.Pesquisar;
import business.Professor;

import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class PesquisarPessoa extends javax.swing.JFrame {
	private JButton jBtnCancelar;
	private JRadioButton jrbtnNome;
	private ButtonGroup btnGroup;
	private JRadioButton jrbtnCPF;
	private JLabel jLabelImagem;
	private JButton jBtnOK;
	private JTextField jTxtFdNome, jTxtfdCPF;
	private String titulo;

	/**
	* Auto-generated main method to display this JFrame
	*/
	
	public PesquisarPessoa(String titulo1) {
		super();
		initGUI();
		this.setTitle("Pesquisar Aluno");
		this.titulo=titulo1;
		
	}
	
	private void initGUI() {
		try {
			AnchorLayout thisLayout = new AnchorLayout();
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			this.setIconImage(new ImageIcon(getClass().getClassLoader().getResource("file/pesquisa2.png")).getImage());
			getContentPane().setForeground(new java.awt.Color(192,192,192));
			{
				jrbtnCPF = new JRadioButton();
				getContentPane().add(jrbtnCPF, new AnchorConstraint(277, 146, 387, 31, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jrbtnCPF.setText("CPF: ");
				jrbtnCPF.setVisible(true);
									
			
				jrbtnNome = new JRadioButton();
				getContentPane().add(jrbtnNome, new AnchorConstraint(70, 156, 179, 31, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jrbtnNome.setText("Nome:");
				jrbtnNome.setVisible(true);
				jrbtnNome.setPreferredSize(new java.awt.Dimension(61, 18));
				jrbtnNome.setSelected(true);

				btnGroup = new ButtonGroup();
				btnGroup.add(jrbtnNome);
				btnGroup.add(jrbtnCPF);
				jrbtnCPF.setPreferredSize(new java.awt.Dimension(56, 18));
				
				
				jrbtnNome.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent arg0) {
						if(jrbtnNome.isSelected()){
							jTxtFdNome.setEnabled(true);
							jTxtfdCPF.setEnabled(false);
						}else
						{
							jTxtFdNome.setEnabled(false);
							jTxtfdCPF.setEnabled(true);				
					     }
					}
				});
				
				jrbtnCPF.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent arg0) {
						if(jrbtnCPF.isSelected()){
							jTxtFdNome.setEnabled(false);
							jTxtfdCPF.setEnabled(true);
						}else if(jrbtnNome.isSelected())
						{
							jTxtFdNome.setEnabled(true);
							jTxtfdCPF.setEnabled(false);				
					     }
					}
				});
								
			}
			{
				jLabelImagem = new JLabel();
				getContentPane().add(jLabelImagem, new AnchorConstraint(3, 1001, 1003, 636, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jLabelImagem.setIcon(new ImageIcon(getClass().getClassLoader().getResource("file/pesquisa.png")));
				jLabelImagem.setPreferredSize(new java.awt.Dimension(175, 153));
			}
			{
				jBtnCancelar = new JButton();
				getContentPane().add(jBtnCancelar, new AnchorConstraint(683, 130, 937, 30, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jBtnCancelar.setPreferredSize(new java.awt.Dimension(48, 39));
				jBtnCancelar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("file/cancelar.jpg")));

				jBtnCancelar.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent arg0) {
						dispose();	
					}
				});
			}
			{
				jBtnOK = new JButton();
				getContentPane().add(jBtnOK, new AnchorConstraint(683, 253, 950, 153, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jBtnOK.setPreferredSize(new java.awt.Dimension(48, 41));
				jBtnOK.setIcon(new ImageIcon(getClass().getClassLoader().getResource("file/ok.jpg")));

				jBtnOK.addActionListener(new ActionListener() {
					
					String cpfPesquisar = jTxtfdCPF.getText();
					
					@Override
					public void actionPerformed(ActionEvent e) {
						
						Pesquisar objetoPesquisar = new Pesquisar();
						if (titulo.equals("Pesquisar Aluno")){
//# FALTA					
							objetoPesquisar.pesquisarAluno(cpfPesquisar);
							
						}
						else if(titulo.equals("Pesquisar Professor")){
//#	FALTA					
							objetoPesquisar.pesquisarProfessor(cpfPesquisar);
						}
						else if(titulo.equals("Pesquisar Funcionario")){
//#	FALTA				
							objetoPesquisar.pesquisarFuncionario(cpfPesquisar);
							
						}
					}
				});
			}
			{
				jTxtfdCPF = new JTextField();
				getContentPane().add(jTxtfdCPF, new AnchorConstraint(271, 564, 399, 169, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jTxtfdCPF.setText("CPF");
				jTxtfdCPF.setPreferredSize(new java.awt.Dimension(193, 21));
				jTxtfdCPF.setEnabled(false);
			}
			{
				jTxtFdNome = new JTextField();
				getContentPane().add(jTxtFdNome, new AnchorConstraint(64, 562, 198, 167, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				jTxtFdNome.setText("Nome");
				jTxtFdNome.setPreferredSize(new java.awt.Dimension(193, 22));
			}
			
			
			
			pack();
			this.setSize(496, 191);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
}
